# 第一阶段：构建应用
FROM node:22-alpine as build-stage
 
WORKDIR /app
 
# 先拷贝package.json（利用Docker缓存层）
COPY package*.json ./
 
# 安装依赖
RUN npm install
 
# 拷贝项目文件
COPY . .
 
# 构建生产环境应用
RUN npm run build
 
FROM nginx:alpine as production-stage
 
# 拷贝自定义Nginx配置
COPY nginx/default.conf /etc/nginx/conf.d/default.conf
 
# 从构建阶段拷贝构建好的文件
COPY --from=build-stage /app/dist /usr/share/nginx/html
 
EXPOSE 80
CMD ["nginx", "-g", "daemon off;"]
